﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LardonPokerSimulator.Model.Deck
{
    public class Cards
    {
        private static Cards CARDS = new Cards();

        private Random _rand = new Random();
        private List<Card> _cardList = new List<Card>();

        private Cards()
        {
            this.GenerateFrenchDeck();   
        }

        private void GenerateFrenchDeck()
        {
            Array suits = Enum.GetValues(typeof(Suit));

            foreach (Suit s in suits)
            {
                for (short i = 1; i <= 13; i++)
                {
                    this._cardList.Add(new Card(i, s));
                }
            }
        }

        public Card PickRandomCard()
        {
            //Get a list of non-used card.
            List<Card> subListe = this._cardList.Where(cl => !cl.IsUsed).ToList();

            //Select one random card in this list.
            Card randomCard = subListe.ElementAt(this._rand.Next(subListe.Count()));

            //Mark card as used
            randomCard.IsUsed = true;

            return randomCard;
        }

       

        #region Static
        public static Cards Instance
        {
            get
            {
                return Cards.CARDS;
            }
        }
        #endregion

    }
}
